//
//  PatientInfoScroll.m
//  Nurse
//
//  Created by Sunny on 14-1-1.
//  Copyright (c) 2014年 Honeywell. All rights reserved.
//

#import "PatientInfoScroll.h"
#import "PatientService.h"

@interface PatientInfoScroll (){
   //
}


@end

@implementation PatientInfoScroll

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setup];
    }
    return self;
}

-(void)awakeFromNib{
    [self setup];
}

-(void)setup{
    
    self.pagingEnabled = YES;
    self.showsHorizontalScrollIndicator = NO;
    self.delegate =self;
}

-(void)loadWithRowNum:(int )rowNum totalNum:(int )totalNum{
     
    int height=16;
    int i=7;
    int size=12;
    
//清空内容 
    for (UIView *aview in self.subviews) {
        [aview removeFromSuperview];
    }
    //double ye=0;
    UILabel *lblks = [[UILabel alloc] initWithFrame:CGRectMake(25, 24, self.width/2, height)];
    UILabel *lbllx = [[UILabel alloc] initWithFrame:CGRectMake(self.width/2+25, 24, self.width/2-10, height)];
    UILabel *lblxb = [[UILabel alloc] initWithFrame:CGRectMake(25, 24+height+i, self.width/2, height)];
    UILabel *lblnl = [[UILabel alloc] initWithFrame:CGRectMake(self.width/2+25, 24+height+i, self.width/2-10, height)];
    UILabel *lblhldj = [[UILabel alloc] initWithFrame:CGRectMake(25, 24+2*(height+i), self.width/2, height)];
    UILabel *lblysdj = [[UILabel alloc] initWithFrame:CGRectMake(self.width/2+25, 24+2*(height+i), self.width/2-10, height)];
    UILabel *lblye = [[UILabel alloc] initWithFrame:CGRectMake(self.width/2+25, 24+3*(height+i), self.width/2, height)];
    UILabel *lblgm = [[UILabel alloc] initWithFrame:CGRectMake(25, 24+3*(height+i), self.width/2, height)];
    UILabel *lblzd = [[UILabel alloc] initWithFrame:CGRectMake(25, 24+4*(height+i), self.width, height)];
    NSDictionary* patient = [[PatientService sharedInstance]currentPatient];
    lblks.font=[UIFont systemFontOfSize:size];
    lbllx.font=[UIFont systemFontOfSize :size];
    lblxb.font=[UIFont systemFontOfSize:size];
    lblnl.font=[UIFont systemFontOfSize:size];
    lblhldj.font=[UIFont systemFontOfSize:size];
    lblysdj.font=[UIFont systemFontOfSize:size];
    lblzd.font=[UIFont systemFontOfSize:size];
    lblye.font=[UIFont systemFontOfSize:size];
    lblgm.font=[UIFont systemFontOfSize:size];
    
    
    lblks.text=nil;
    lbllx.text=nil;
    lblxb.text=nil;
    lblnl.text=nil;
    lblhldj.text=nil;
    lblysdj.text=nil;
    lblzd.text=nil;
    lblye.text=nil;
    lblgm.text=nil;
    
    
    lblks.text=[NSString stringWithFormat:@"所属科室:%@",[patient valueForKey:@"所属科室"]];//[patient valueForKey:@"所属科室"];
    
    //176,183,193
    //lblks.textColor=[UIColor colorWithRed:176/255.0 green:183/255.0 blue:193/255.0 alpha:0.6];
    lbllx.text=[NSString stringWithFormat:@"病人类型:%@",[patient valueForKey:@"记帐代码"]];
    lblxb.text=[NSString stringWithFormat:@"性别:%@",[patient valueForKey:@"性别"]];
    lblnl.text=[NSString stringWithFormat:@"年龄:%@",[patient valueForKey:@"年龄"]];
    lblhldj.text=[NSString stringWithFormat:@"护理等级:%@",[patient valueForKey:@"护理等级"]];
    lblysdj.text=[NSString stringWithFormat:@"饮食类型:%@",[patient valueForKey:@"饮食类型"]];
    lblzd.text=[NSString stringWithFormat:@"入院诊断:%@",[patient valueForKey:@"入院诊断"]];
    //ye=[patient valueForKey:@"预交金额"];
    //[NSString stringWithFormat:@"%0.2f",ye];
    double money =[(id)[patient valueForKey:@"预交金额"] doubleValue];
    lblye.text=[NSString stringWithFormat:@"剩余金额:%.2f",money];
    
    lblgm.text=[NSString stringWithFormat:@"过敏情况:%@",[patient valueForKey:@"过敏情况"]];
    
    if ([patient valueForKey:@"预交金额"] !=nil) {
        if ([[patient valueForKey:@"预交金额"] doubleValue]> 0) {
            lblye.textColor = [UIColor blackColor];
        }else{
            lblye.textColor = [UIColor redColor];
        }
        //value = [NSString stringWithFormat:@"%.2f",[yuEr doubleValue]];
    }

    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];
    [self addSubview:lblks];
    [self addSubview:lbllx];
    [self addSubview:lblxb];
    [self addSubview:lblnl];
    [self addSubview:lblhldj];
    [self addSubview:lblysdj];
    [self addSubview:lblzd];
    [self addSubview:lblye];
    [self addSubview:lblgm];


    
    
}

#pragma mark Scrollview delegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
   
    self.pageC.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
